package com.orphan.marketBack.service.impl;

import com.orphan.marketBack.dao.PurchaseMapper;
import com.orphan.marketBack.po.Purchase;
import com.orphan.marketBack.service.PurchaseService;
import com.orphan.marketBack.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PurchaseServiceImpl implements PurchaseService {
    @Autowired
    private PurchaseMapper purchaseMapper;

    @Override
    public boolean insert(Purchase purchase) {
        int i = purchaseMapper.insert(purchase);
        boolean flag = false;
        if (i > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public ResultVO selectPurchase() {
        List<Purchase> purchases = purchaseMapper.selectPurchase();

        ResultVO resultVO = new ResultVO();
        resultVO.setData(purchases);
        resultVO.setTotal(purchases.size());

        return resultVO;
    }

    @Override
    public ResultVO selectPurchaseById(String purchaseId) {
        List<Purchase> list = purchaseMapper.selectPurchaseById(purchaseId);

        ResultVO resultVO = new ResultVO();
        resultVO.setData(list);
        resultVO.setTotal(list.size());

        return resultVO;
    }
}
